package com.sgb.kjwl.viewmodel.home;

import android.text.TextUtils;
import android.util.Log;

import androidx.databinding.ObservableField;

import com.google.gson.reflect.TypeToken;
import com.sgb.kjwl.api.APIManager;
import com.swgk.core.base.api.ICallBack;
import com.sgb.kjwl.model.entity.BiddingEntity;
import com.sgb.jicai.entity.CentralizedMiningEntity;
import com.swgk.core.base.model.entity.H5ReEntity;
import com.swgk.core.util.PickSelectEntity;
import com.sgb.jicai.entity.JiCaiHomeListRequestBean;
import com.sgb.kjwl.model.entity.lease.AskLeaseSheBeiEntity;
import com.sgb.kjwl.model.entity.lease.LeaseListEntity;
import com.sgb.kjwl.model.entity.request.CarFilterJson;
import com.sgb.kjwl.model.entity.request.FactoryFilterJson;
import com.sgb.kjwl.model.entity.request.FarmFilterJson;
import com.sgb.kjwl.model.entity.request.HouseFilterJson;
import com.sgb.kjwl.model.entity.request.LandFilterJson;
import com.sgb.kjwl.model.entity.request.LeaseAskFilterJson;
import com.sgb.kjwl.model.entity.request.LeaseMachineFilterJson;
import com.sgb.kjwl.model.entity.request.MachineFilterJson3;
import com.sgb.kjwl.model.entity.supplier3.DictEntity3;
import com.swgk.core.base.model.entity.ListResponse;
import com.sgb.kjwl.repository.HomeRepertory;
import com.sgb.kjwl.view.ui.activity.WebViewX5HostActivity;
import com.swgk.core.mmkvutil.CacheMarker;
import com.sgb.kjwl.view.ui.fragment.home.LeasingMachineryFragment;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.mmkvutil.MkvUtils;
import com.swgk.core.mmkvutil.DatalUtils;
import com.swgk.core.util.MToast;
import com.swgk.core.util.SharedPreferenceUtil;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class LeasingMachineryModel extends BaseViewModel {
    public HomeRepertory repertory;
    private LeasingMachineryFragment fragment;
    public MachineFilterJson3 filterJson1 = new MachineFilterJson3();
    public MachineFilterJson3 filterJson2 = new MachineFilterJson3();
    public MachineFilterJson3 filterJson3 = new MachineFilterJson3();
    public LeaseMachineFilterJson machineFilterJson3 = new LeaseMachineFilterJson();
    public HouseFilterJson filterJson4 = new HouseFilterJson();
    public ObservableField<LandFilterJson> filterJson5 = new ObservableField<>(new LandFilterJson());
    public ObservableField<FactoryFilterJson> filterJson6 = new ObservableField<>(new FactoryFilterJson());
    public ObservableField<FarmFilterJson> filterJson = new ObservableField<>(new FarmFilterJson());
    public int pageSize = 6;
    public int pageNum = 1;
    private String localLng;
    private String localLat;
    private List<PickSelectEntity> list = new ArrayList<>();

    public LeasingMachineryModel(LeasingMachineryFragment fragment, HomeRepertory repertory) {
        this.fragment = fragment;
        this.repertory = repertory;
        localLng = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LONGITUDE_ID, "");
        localLat = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LATITUDE_ID, "");
    }

    /*
     * 获取二级类目
     * */
    public void getSecondType(int mItemType) {
        switch (mItemType) {
            case 0:
                list.clear();
                list.add(new PickSelectEntity("0", "全部"));
                list.add(new PickSelectEntity("1", "机械"));
                list.add(new PickSelectEntity("2", "设备"));
                list.add(new PickSelectEntity("3", "车辆"));
                list.add(new PickSelectEntity("4", "房产"));
                list.add(new PickSelectEntity("5", "土地"));
                list.add(new PickSelectEntity("6", "工厂"));
                list.add(new PickSelectEntity("7", "农机"));
                fragment.showLeaseTypeView(list);
                break;
            case 1:
                list.clear();
                list.add(new PickSelectEntity("0", "求租信息"));
                list.add(new PickSelectEntity("1", "竞价租赁"));
                list.add(new PickSelectEntity("2", "集采租赁"));
                fragment.showLeaseNeedView(list);
                break;
        }
    }

    public void getThreeTypeModel(int type) {
        switch (type){
            case 1://机械
                APIManager.getInstance().getLeaseAPI().getCategorySelectMachine().enqueue(new ICallBack<BaseEntity<List<DictEntity3>>>() {
                    @Override
                    public void onSuccess(BaseEntity<List<DictEntity3>> data) {
                        if (data.getState().equals(APIManager.RESPONSE_OK)) {
                            List<DictEntity3> dictEntity3List = data.getData();
                            if (dictEntity3List != null && dictEntity3List.size() > 0)
                                dictEntity3List.get(0).setName("全部");
                            fragment.showLeaseThreeTypeView(data.getData());
                        }
                    }
                });
                break;
            case 2://设备
                APIManager.getInstance().getLeaseAPI().getCategorySelectDevice().enqueue(new ICallBack<BaseEntity<List<DictEntity3>>>() {
                    @Override
                    public void onSuccess(BaseEntity<List<DictEntity3>> data) {
                        if (data.getState().equals(APIManager.RESPONSE_OK)) {
                            List<DictEntity3> dictEntity3List = data.getData();
                            if (dictEntity3List != null && dictEntity3List.size() > 0)
                                dictEntity3List.get(0).setName("全部");
                            fragment.showLeaseThreeTypeView(data.getData());
                        }
                    }
                });
                break;
            case 3://车辆
                APIManager.getInstance().getLeaseAPI().getCategorySelectCar().enqueue(new ICallBack<BaseEntity<List<DictEntity3>>>() {
                    @Override
                    public void onSuccess(BaseEntity<List<DictEntity3>> data) {
                        if (data.getState().equals(APIManager.RESPONSE_OK)) {
                            List<DictEntity3> dictEntity3List = data.getData();
                            if (dictEntity3List != null && dictEntity3List.size() > 0)
                                dictEntity3List.get(0).setName("全部");
                            fragment.showLeaseThreeTypeView(data.getData());
                        }
                    }
                });
                break;
            case 4://房产
                APIManager.getInstance().getLeaseAPI().getParentEstateTypeHouse().enqueue(new ICallBack<BaseEntity<List<DictEntity3>>>() {
                    @Override
                    public void onSuccess(BaseEntity<List<DictEntity3>> data) {
                        if (data.getState().equals(APIManager.RESPONSE_OK)) {
                            List<DictEntity3> dictEntity3List = data.getData();
                            if (dictEntity3List != null && dictEntity3List.size() > 0)
                                dictEntity3List.get(0).setName("全部");
                            fragment.showLeaseThreeTypeView(data.getData());
                        }
                    }
                });
                break;
            case 5://土地
                APIManager.getInstance().getLeaseAPI().getParentEstateTypeLand().enqueue(new ICallBack<BaseEntity<List<DictEntity3>>>() {
                    @Override
                    public void onSuccess(BaseEntity<List<DictEntity3>> data) {
                        if (data.getState().equals(APIManager.RESPONSE_OK)) {
                            List<DictEntity3> dictEntity3List = data.getData();
                            if (dictEntity3List != null && dictEntity3List.size() > 0)
                                dictEntity3List.get(0).setName("全部");
                            fragment.showLeaseThreeTypeView(data.getData());
                        }
                    }
                });
                break;
            case 6://工厂
                APIManager.getInstance().getLeaseAPI().getCategorySelectFactory("0").enqueue(new ICallBack<BaseEntity<List<DictEntity3>>>() {
                    @Override
                    public void onSuccess(BaseEntity<List<DictEntity3>> data) {
                        if (data.getState().equals(APIManager.RESPONSE_OK)) {
                            List<DictEntity3> dictEntity3List = data.getData();
                            if (dictEntity3List != null && dictEntity3List.size() > 0)
                                dictEntity3List.get(0).setName("全部");
                            fragment.showLeaseThreeTypeView(data.getData());
                        }
                    }
                });
                break;
            case 7://农机
                APIManager.getInstance().getLeaseAPI().getCategorySelectFarm("0").enqueue(new ICallBack<BaseEntity<List<DictEntity3>>>() {
                    @Override
                    public void onSuccess(BaseEntity<List<DictEntity3>> data) {
                        if (data.getState().equals(APIManager.RESPONSE_OK)) {
                            List<DictEntity3> dictEntity3List = data.getData();
                            if (dictEntity3List != null && dictEntity3List.size() > 0)
                                dictEntity3List.get(0).setName("全部");
                            fragment.showLeaseThreeTypeView(data.getData());
                        }
                    }
                });
                break;
        }
    }

    public void getThreeTypeNeedModel(int type) {
        switch (type) {
            case 0:
                list.clear();
                list.add(new PickSelectEntity("0", "全部"));
                list.add(new PickSelectEntity("1", "机械求租"));
                list.add(new PickSelectEntity("2", "设备求租"));
                list.add(new PickSelectEntity("3", "车辆求租"));
                list.add(new PickSelectEntity("4", "房产求租"));
                list.add(new PickSelectEntity("5", "土地求租"));
                list.add(new PickSelectEntity("6", "工厂求租"));
                list.add(new PickSelectEntity("7", "农机求租"));
                break;
            case 1:
            case 2:
                list.clear();
                list.add(new PickSelectEntity("0", "全部"));
                list.add(new PickSelectEntity("1", "机械租赁"));
                list.add(new PickSelectEntity("2", "设备租赁"));
                break;
        }
        fragment.showThreeLeaseNeedView(list);
    }

    /**
     * 出租详情
     *
     * @param type
     * @param id
     */
    public void getH5Url(String type, String id) {
        String name = "";
        if ("1".equals(type)) {
            name = "mechanicsDetail";//机械
        } else if ("2".equals(type)) {
            name = "equipmentDetails";//设备
        } else if ("3".equals(type)) {
            name = "vehicleDetails";//车辆
        } else if ("4".equals(type)) {
            name = "propertyDetails";//房产
        } else if ("5".equals(type)) {
            name = "landDetails";//土地
        } else if ("6".equals(type)) {
            name = "factoryDetails";//工厂
        } else if ("7".equals(type)) {
            name = "farmDetail";//农机
        }
        if (TextUtils.isEmpty(name)) {
            return;
        }
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPickAPI().getUrlSetting(name).enqueue(new Callback<BaseEntity<H5ReEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<H5ReEntity>> call, Response<BaseEntity<H5ReEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }

                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    String url = response.body().getData().getUrl() + "?id=" + id + "&iosFlag=1";
//                    WebViewX5HostActivity.start(fragment.getActivity(), url);
                    WebViewX5HostActivity.start(fragment.getActivity(), url,id,"lease",type);
                } else {
                    MToast.showToast(fragment.getActivity(), response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<H5ReEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    /**
     * 求租详情
     *
     * @param categoryType
     * @param id
     */
    public void getH5UrlByAskLease(String categoryType, String id) {
        String urlName = "";
        if ("1".equals(categoryType)) {//机械
            urlName = "mechanicsRentDetails";
        } else if ("2".equals(categoryType)) {//设备
            urlName = "equipmentRentDetails";
        } else if ("3".equals(categoryType)) {//车辆
            urlName = "vehicleRentDetails";
        } else if ("4".equals(categoryType)) {//房产
            urlName = "houseRentDetails";
        } else if ("5".equals(categoryType)) {//土地
            urlName = "landRentDetails";
        } else if ("6".equals(categoryType)) {//工厂
            urlName = "factoryRentDetails";
        } else if ("7".equals(categoryType)) {//农机
            urlName = "farmRentDetails";
        }
        if (TextUtils.isEmpty(urlName)) {
            return;
        }
        DialogHelper.showProgressDialog(fragment.getActivity(), "加载中...").setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPickAPI().getUrlSetting(urlName).enqueue(new Callback<BaseEntity<H5ReEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<H5ReEntity>> call, Response<BaseEntity<H5ReEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    String url = response.body().getData().getUrl() + "?id=" + id;
//                    WebViewX5HostActivity.start(fragment.getActivity(), url);
                    WebViewX5HostActivity.start(fragment.getActivity(), url,id,"asklease",categoryType);
                } else {
                    MToast.showToast(fragment.getActivity(), response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<H5ReEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    /**
     * 竞价租赁详情
     *
     * @param id
     */
    public void getUrlSetting(String id) {
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPickAPI().getUrlSetting("competitivePurchase").enqueue(new ICallBack<BaseEntity<H5ReEntity>>() {
            @Override
            public void onSuccess(BaseEntity<H5ReEntity> data) {
                if (data == null || data.getState() == null) {
                    return;
                }

                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    String url = data.getData().getUrl() + "?id=" + id;
                    String lng = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LONGITUDE_ID, "");
                    String lat = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LATITUDE_ID, "");
                    url = url + "&lng=" + lng + "&lat=" + lat;
                    WebViewX5HostActivity.start(fragment.getActivity(), url, id);
                } else {
                    MToast.showToast(fragment.getActivity(), data.getMsg());
                }
            }
        });
    }

    /**
     * 集采详情
     *
     * @param id
     */
    public void getH5UrlByJC(String id) {
        DialogHelper.showProgressDialog(fragment.getActivity(), "加载中...").setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPickAPI().getUrlSetting("collection").enqueue(new ICallBack<BaseEntity<H5ReEntity>>() {
            @Override
            public void onSuccess(BaseEntity<H5ReEntity> data) {
                DialogHelper.dismissProgressDialog();
                if (data == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(APIManager.RESPONSE_OK)) {//type 0 首页 1 我的集采 2 我的报价
                    SharedPreferenceUtil.init(fragment.getActivity());
                    String token = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.resourceAPPToken, "");
                    String url = data.getData().getUrl() + "?id=" + id + "&type=0" + "&token=" + token;
                    WebViewX5HostActivity.start(fragment.getActivity(), url);
                } else {
                    MToast.showToast(fragment.getActivity(), data.getMsg());
                }
            }
        });
    }

    /**
     * 出租大厅 全部/机械列表
     *
     * @param isLoadMore
     */
    public void getMachineModel(int pos, String firstCategoryNo, boolean isLoadMore) {
        pageNum = isLoadMore ? pageNum + 1 : 1;
        LeaseMachineFilterJson filterJson = new LeaseMachineFilterJson();
        filterJson.setFirstCategoryNo(firstCategoryNo);
        filterJson.setPageNum(pageNum);
        filterJson.setPageSize(pageSize);
        filterJson.setSortWay("5");
        filterJson.setType(pos == 0 ? "" : String.valueOf(pos));
        if (repertory.getIsLocal()) {
            //经度
            filterJson.setLatitude("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""))
                    ? repertory.getLatitude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""));
            //纬度
            filterJson.setLongitude("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""))
                    ? repertory.getLongititude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""));
        } else {
            //经度
            filterJson.setLongitude(repertory.getLongititude());
            //纬度
            filterJson.setLatitude(repertory.getLatitude());
        }

        if (pageNum != 1 && fragment.getPosition() != 0) {
            DialogHelper.showProgressDialog(fragment.getActivity(), "加载中...", 0, false).setCanceledOnTouchOutside(false);
        }
        /*if (pageNum == 1 && fragment.getPosition() == 0 && !fragment.getIsRefresh()) {
            Type type = new TypeToken<ListResponse<List<LeaseListEntity>>>() {
            }.getType();
            Object object = DatalUtils.getInstance().getData(MkvUtils.CacheModular, getSwithType(firstCategoryNo), type);
            if (object != null) {
                ListResponse<List<LeaseListEntity>> cacheMateialDataList = (ListResponse<List<LeaseListEntity>>) object;
                fragment.showLeaseList(cacheMateialDataList.getList(), isLoadMore);
                return;
            }
        }*/
        APIManager.getInstance().getLeaseAPI().rentalAndEmployedHall(filterJson).enqueue(new Callback<BaseEntity<ListResponse<List<LeaseListEntity>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<ListResponse<List<LeaseListEntity>>>> call, Response<BaseEntity<ListResponse<List<LeaseListEntity>>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }
                if (response.body().getData()==null){
                    fragment.showLeaseList(new ArrayList<>(), isLoadMore);
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    fragment.showLeaseList(response.body().getData().getList(), isLoadMore);
                    /*if (pageNum == 1 && fragment.getPosition() == 0) {
                        String cacheMateialistlHash = DatalUtils.getHashData(MkvUtils.CacheModular, getSwithType(firstCategoryNo));
                        //获取从网络请求下来的数据的哈希值
                        String mHashNet = DatalUtils.getInstance().strToHashKey(response.body().getData());
                        if (!cacheMateialistlHash.equals(mHashNet)) {
                            if(response.body().getData()!=null) {
                                fragment.showLeaseList(response.body().getData().getList(), isLoadMore);
                            }
                            DatalUtils.getInstance().putData(MkvUtils.CacheModular, getSwithType(firstCategoryNo), response.body().getData());
                        }
                    } else {
                        fragment.showLeaseList(response.body().getData().getList(), isLoadMore);
                    }*/
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ListResponse<List<LeaseListEntity>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    //获取车辆筛选列表
    public void getAllListByCar(String FirstCategoryNo, boolean isLoadMore) {
        pageNum = isLoadMore ? pageNum + 1 : 1;
        CarFilterJson filterJson = new CarFilterJson();
        filterJson.setPageNum(pageNum);
        filterJson.setPageSize(pageSize);
        filterJson.setModelId(FirstCategoryNo);
        filterJson.setSortWay("5");
        filterJson.setBrandId("");
        filterJson.setType("3");
        if (repertory.getIsLocal()) {
            //经度
            filterJson.setLatitude("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""))
                    ? repertory.getLatitude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""));
            //纬度
            filterJson.setLongitude("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""))
                    ? repertory.getLongititude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""));
        } else {
            //经度
            filterJson.setLongitude(repertory.getLongititude());
            //纬度
            filterJson.setLatitude(repertory.getLatitude());
        }
        DialogHelper.showProgressDialog(fragment.getContext(), "加载中...").setCanceledOnTouchOutside(false);
        APIManager.getInstance().getLeaseAPI().rentalAndEmployedHall(filterJson)
                .enqueue(new Callback<BaseEntity<ListResponse<List<LeaseListEntity>>>>() {
                    @Override
                    public void onResponse(Call<BaseEntity<ListResponse<List<LeaseListEntity>>>> call, Response<BaseEntity<ListResponse<List<LeaseListEntity>>>> response) {
                        DialogHelper.dismissProgressDialog();
                        if (response.body() == null || response.body().getState() == null) {
                            return;
                        }
                        if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                            fragment.showLeaseList(response.body().getData().getList(), isLoadMore);
                        }

                    }

                    @Override
                    public void onFailure(Call<BaseEntity<ListResponse<List<LeaseListEntity>>>> call, Throwable t) {
                        DialogHelper.dismissProgressDialog();
                    }
                });
    }


    //获取房产筛选列表
    public void getAllListByHouse(String FirstCategoryNo, boolean isLoadMore) {
        pageNum = isLoadMore ? pageNum + 1 : 1;
        HouseFilterJson filterJson = new HouseFilterJson();
        filterJson.setPageNum(pageNum);
        filterJson.setPageSize(pageSize);
        filterJson.setSortWay("5");
        filterJson.setCategoryParentId(FirstCategoryNo);
        filterJson.setCategoryChildId("");
        filterJson.setRentalArea("");
        filterJson.setType("4");
        if (repertory.getIsLocal()) {
            //经度
            filterJson.setLatitude("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""))
                    ? repertory.getLatitude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""));
            //纬度
            filterJson.setLongitude("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""))
                    ? repertory.getLongititude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""));
        } else {
            //经度
            filterJson.setLongitude(repertory.getLongititude());
            //纬度
            filterJson.setLatitude(repertory.getLatitude());
        }
        DialogHelper.showProgressDialog(fragment.getContext(), "加载中...").setCanceledOnTouchOutside(false);
        APIManager.getInstance().getLeaseAPI().rentalAndEmployedHall(filterJson)
                .enqueue(new Callback<BaseEntity<ListResponse<List<LeaseListEntity>>>>() {
                    @Override
                    public void onResponse(Call<BaseEntity<ListResponse<List<LeaseListEntity>>>> call, Response<BaseEntity<ListResponse<List<LeaseListEntity>>>> response) {
                        DialogHelper.dismissProgressDialog();
                        if (response.body() == null || response.body().getState() == null) {
                            return;
                        }
                        if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                            fragment.showLeaseList(response.body().getData().getList(), isLoadMore);
                        }

                    }

                    @Override
                    public void onFailure(Call<BaseEntity<ListResponse<List<LeaseListEntity>>>> call, Throwable t) {
                        DialogHelper.dismissProgressDialog();
                    }
                });
    }


    //获取土地筛选列表
    public void getAllListByLand(String FirstCategoryNo, boolean isLoadMore) {
        pageNum = isLoadMore ? pageNum + 1 : 1;
        LandFilterJson filterJson = new LandFilterJson();
        filterJson.setPageNum(pageNum);
        filterJson.setPageSize(pageSize);
        filterJson.setSortWay("5");
        filterJson.setFirstCategoryNo(FirstCategoryNo);
        filterJson.setSecondCategoryNo("");
        filterJson.setRentalArea("");
        filterJson.setType("5");
        if (repertory.getIsLocal()) {
            //经度
            filterJson.setLatitude("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""))
                    ? repertory.getLatitude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""));
            //纬度
            filterJson.setLongitude("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""))
                    ? repertory.getLongititude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""));
        } else {
            //经度
            filterJson.setLongitude(repertory.getLongititude());
            //纬度
            filterJson.setLatitude(repertory.getLatitude());
        }
        DialogHelper.showProgressDialog(fragment.getContext(), "加载中...").setCanceledOnTouchOutside(false);
        APIManager.getInstance().getLeaseAPI().rentalAndEmployedHall(filterJson)
                .enqueue(new Callback<BaseEntity<ListResponse<List<LeaseListEntity>>>>() {
                    @Override
                    public void onResponse(Call<BaseEntity<ListResponse<List<LeaseListEntity>>>> call, Response<BaseEntity<ListResponse<List<LeaseListEntity>>>> response) {
                        DialogHelper.dismissProgressDialog();
                        if (response.body() == null || response.body().getState() == null) {
                            return;
                        }
                        if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                            fragment.showLeaseList(response.body().getData().getList(), isLoadMore);
                        }

                    }

                    @Override
                    public void onFailure(Call<BaseEntity<ListResponse<List<LeaseListEntity>>>> call, Throwable t) {
                        DialogHelper.dismissProgressDialog();
                    }
                });
    }

    //获取工厂筛选列表
    public void getAllListByFactory(String FirstCategoryNo, boolean isLoadMore) {
        pageNum = isLoadMore ? pageNum + 1 : 1;
        FactoryFilterJson filterJson = new FactoryFilterJson();
        filterJson.setPageNum(pageNum);
        filterJson.setPageSize(pageSize);
        filterJson.setSortWay("5");
        filterJson.setFirstCategoryNo(FirstCategoryNo);
        filterJson.setSecondCategoryNo("");
        filterJson.setRentalArea("");
        filterJson.setType("6");
        if (repertory.getIsLocal()) {
            //经度
            filterJson.setLatitude("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""))
                    ? repertory.getLatitude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""));
            //纬度
            filterJson.setLongitude("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""))
                    ? repertory.getLongititude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""));
        } else {
            //经度
            filterJson.setLongitude(repertory.getLongititude());
            //纬度
            filterJson.setLatitude(repertory.getLatitude());
        }
        DialogHelper.showProgressDialog(fragment.getContext(), "加载中...").setCanceledOnTouchOutside(false);
        APIManager.getInstance().getLeaseAPI().rentalAndEmployedHall(filterJson)
                .enqueue(new Callback<BaseEntity<ListResponse<List<LeaseListEntity>>>>() {
                    @Override
                    public void onResponse(Call<BaseEntity<ListResponse<List<LeaseListEntity>>>> call, Response<BaseEntity<ListResponse<List<LeaseListEntity>>>> response) {
                        DialogHelper.dismissProgressDialog();
                        if (response.body() == null || response.body().getState() == null) {
                            return;
                        }
                        if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                            fragment.showLeaseList(response.body().getData().getList(), isLoadMore);
                        }

                    }

                    @Override
                    public void onFailure(Call<BaseEntity<ListResponse<List<LeaseListEntity>>>> call, Throwable t) {
                        DialogHelper.dismissProgressDialog();
                    }
                });
    }

    //获取农机筛选列表
    public void getAllListByFram(String FirstCategoryNo, boolean isLoadMore) {
        pageNum = isLoadMore ? pageNum + 1 : 1;
        FarmFilterJson filterJson = new FarmFilterJson();
        filterJson.setPageNum(pageNum);
        filterJson.setPageSize(pageSize);
        filterJson.setSortWay("5");
        filterJson.setFirstCategoryNo(FirstCategoryNo);
        filterJson.setSecondCategoryNo("");
        filterJson.setType("7");
        if (repertory.getIsLocal()) {
            //经度
            filterJson.setLatitude("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""))
                    ? repertory.getLatitude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""));
            //纬度
            filterJson.setLongitude("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""))
                    ? repertory.getLongititude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""));
        } else {
            //经度
            filterJson.setLongitude(repertory.getLongititude());
            //纬度
            filterJson.setLatitude(repertory.getLatitude());
        }
        DialogHelper.showProgressDialog(fragment.getContext(), "加载中...").setCanceledOnTouchOutside(false);
        APIManager.getInstance().getLeaseAPI().rentalAndEmployedHall(filterJson)
                .enqueue(new Callback<BaseEntity<ListResponse<List<LeaseListEntity>>>>() {
                    @Override
                    public void onResponse(Call<BaseEntity<ListResponse<List<LeaseListEntity>>>> call, Response<BaseEntity<ListResponse<List<LeaseListEntity>>>> response) {
                        DialogHelper.dismissProgressDialog();
                        if (response.body() == null || response.body().getState() == null) {
                            return;
                        }
                        if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                            fragment.showLeaseList(response.body().getData().getList(), isLoadMore);
                        }

                    }

                    @Override
                    public void onFailure(Call<BaseEntity<ListResponse<List<LeaseListEntity>>>> call, Throwable t) {
                        DialogHelper.dismissProgressDialog();
                    }
                });
    }

    /**
     * 求租信息
     *
     * @param categoryType
     * @param classNo
     * @param isLoadMore
     */
    public void getDataList(String categoryType, String classNo, boolean isLoadMore) {
        pageNum = isLoadMore ? pageNum + 1 : 1;
        LeaseAskFilterJson filterJson = new LeaseAskFilterJson();
        filterJson.setType(categoryType);
        filterJson.setFirstCategoryNo(classNo);
        filterJson.setProvinceNo("");
        filterJson.setCityNo("");
        filterJson.setLimit(3);
        filterJson.setCurrent(pageNum);
        filterJson.setSortWay("1");
        filterJson.setAreaNos(new ArrayList<>());
        APIManager.getInstance().getMachineAPI().getAskRentLeaseAll(filterJson).enqueue(new Callback<BaseEntity<ListResponse<List<AskLeaseSheBeiEntity>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<ListResponse<List<AskLeaseSheBeiEntity>>>> call, Response<BaseEntity<ListResponse<List<AskLeaseSheBeiEntity>>>> response) {
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }

                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    if (null != response.body().getData()) {
                        fragment.showAskRentList(response.body().getData().getList(), isLoadMore);
                    } else {
                        MToast.showToast(fragment.getActivity(), "暂无数据");
                    }
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ListResponse<List<AskLeaseSheBeiEntity>>>> call, Throwable t) {
                Log.v("dd", "sdsdd");
            }
        });
    }


    /**
     * 竞价租赁
     *
     * @param goodsType
     * @param b
     */
    public void getBiddingList(String goodsType, boolean b) {
        HashMap map = new HashMap();
        pageNum = b ? pageNum + 1 : 1;
        map.put("limit", 3);
        map.put("name", "");
        map.put("page", pageNum);
        map.put("type", "1");
        //map.put("areacode", repertory.getAreaCode());
        map.put("goodsType", goodsType);
        map.put("sortMethod", "1");
        DialogHelper.showProgressDialog(fragment.getActivity(), "加载中...").setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPickAPI().getBiddingList(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<BiddingEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<BiddingEntity>>> data) {
                DialogHelper.dismissProgressDialog();
                if (data == null || data.getState() == null) {
                    return;
                }

                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    fragment.showBindingList(data.getData().getList(), b);
                } else {
                    MToast.showToast(fragment.getActivity(), data.getMsg());
                }
            }
        });
    }

    /**
     * 需方发起列表
     */
    public void getJiCaiList(JiCaiHomeListRequestBean map, boolean isLoadMore) {
        DialogHelper.showProgressDialog(fragment.getActivity(), "加载中...").setCanceledOnTouchOutside(false);
        pageNum = isLoadMore ? pageNum + 1 : 1;
        //map.setProvinceNo(repertory.getAreaCode());
        map.setCurrent(pageNum);
        map.setLimit(3);
        APIManager.getInstance().getCentralizedMiningAPI().getJiCaiLists(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<CentralizedMiningEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<CentralizedMiningEntity>>> data) {
                DialogHelper.dismissProgressDialog();
                if (data == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    fragment.showCentralizedMiningCuttingLineList(data.getData().getList(), isLoadMore);
                } else {
                    MToast.showToast(fragment.getContext(), data.getMsg());
                }
            }
        });
    }

    /**
     * 是否有缓存
     *
     * @param TYPE
     */
    public boolean getCacheData(String TYPE) {
        if (fragment.getPosition() == 0) {
            Type type = new TypeToken<List<DictEntity3>>() {
            }.getType();
            Object object = DatalUtils.getInstance().getData(MkvUtils.CacheModular, TYPE, type);
            if (object != null) {
                List<DictEntity3> cacheMateialDataList = (List<DictEntity3>) object;
                fragment.showType(cacheMateialDataList);
                return true;
            }
        }
        return false;
    }

    /**
     * 是否更新缓存
     *
     * @param TYPE
     * @param dataList
     */
    public void setCacheData(String TYPE, List<DictEntity3> dataList) {
        if (fragment.getPosition() == 0) {
            String cacheMateialistlHash = DatalUtils.getHashData(MkvUtils.CacheModular, TYPE);
            //获取从网络请求下来的数据的哈希值
            String mHashNet = DatalUtils.getInstance().strToHashKey(dataList);
            if (!cacheMateialistlHash.equals(mHashNet)) {
                fragment.showType(dataList);
                DatalUtils.getInstance().putData(MkvUtils.CacheModular, TYPE, dataList);
            }
        } else {
            fragment.showType(dataList);
        }
    }

    /**
     * 根据当前标记来生成缓存标记
     *
     * @param type
     * @return
     */
    private String getSwithType(String type) {
        return CacheMarker.firstCategory + type;
    }
}
